<?php
namespace app\admin\controller;

use \think\Controller;
use \think\Db;
use think\Session;
use app\admin\model\Login;
class Index extends Controller
{
    public function index()
    {
        if(request()->isPost()) {
            //验证码
            if (!captcha_check(input('verifycode'))) {
                //验证
                echo "<script>alert('验证码错误');</script>";
            } else {
            	$a=input('adminname');
            	$p=input('password');
            	$log= new Login;
            	
            	$result=$log->login($a,$p);
            	
            	if($result==1){
            		echo "<script>alert('密码错误');</script>";
            	}
            	else if($result==2){
            		echo "<script>alert('用户不存在');</script>";
            		
            	}
            	else{
            		$this->redirect('video/index');
            	}
                //用户名是否存在
                //select * from admins where adminname='$admin'
        

                //密码是否正确

                //正确，保存管理员信息到session

            }
        }
        return $this->fetch();
    }

    public function logout(){
        Session::clear();
        $this->redirect('index/index');
    }


        public function show_captcha(){
        ob_clean();
        $captcha = new \think\captcha\Captcha();
        $captcha->useZh=true;
        $captcha->zhSet="YHC123";
        $captcha->fontSize = 20;
        $captcha->length   = 3;
        $captcha->useNoise = false;
        return $captcha->entry();
    }
    
}
